package com.at.interceptor;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author : code1997
 * @date :2020-09-2020/9/28 11:14
 */
public class LoginInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //判断用户是否登录
        Object user = request.getSession().getAttribute("user");
        if (user==null){
            //说明未登录
            response.sendRedirect("/admin");
            return false;
        }
        return true;
    }
}
